package com.ruoyi.web.controller.wechat;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.wechat.domain.WechatLoginRequestData;
import com.ruoyi.wechat.service.IWxLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.domain.AjaxResult;

@RestController
@RequestMapping("/wechat")
public class WxLoginController extends BaseController {
    @Autowired
    private IWxLoginService wxLoginService;

    /**
     * 小程序登录接口
     * @param wechatLoginRequestData 登录入参
     * @return Token和用户信息
     */
    @PostMapping("/login")
    public AjaxResult wechatLogin(@RequestBody WechatLoginRequestData wechatLoginRequestData) {
        try {
            String token = wxLoginService.miniAppLogin(wechatLoginRequestData.getCode());
            return AjaxResult.success("登录成功", token);
        } catch (Exception e) {
            return AjaxResult.error("登录失败：" + e.getMessage());
        }
    }
}